/*******************************************************************************
 * StandardPlaylistManager.h
 *
 * Copyright (c) 2012, Varuna L Amachi. All rights reserved.
 *
 * This program/library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This program/library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 ******************************************************************************/

#ifndef STANDARDPLAYLISTMANAGER_H
#define STANDARDPLAYLISTMANAGER_H

#include <QHash>
#include <QList>

#include "core/model/SavedPlaylist.h"
#include "core/components/AbstractPlaylistManager.h"
#include "core/model/AudioTrack.h"


namespace Tanyatu
{
namespace Component
{
class TANYATU_CORE_EXPORT StandardPlaylistManager :
        public AbstractPlaylistManager
{
    Q_OBJECT

public:
    StandardPlaylistManager( QObject *parent = 0 );

    virtual ~StandardPlaylistManager();

    void appendToPlaylist( QString playlistName, QString trackId );

    bool deletePlaylist( QString playlistName );

    bool createPlaylist( QString playlistName);

    bool setTrackIdList( QString playlistName,
                       QList< QString > &list);

    bool clearPlaylist( QString playlistName );

    bool deleteAllPlaylists();

    void clear();

    void onPlaylistSelected( QString playlistName );

    void onItemRemovalFromStorage( QString trackId );

    void ratePlaylist( QString playlistName,
                               Model::MediaRating rating);

    void tagItem( QString playlistName, QString tag );

    void removeItemTag( QString playlistName, QString tag );


    bool hasPlaylist( QString playlistName );

    const QList< QString > trackIdsIn( QString playlistName );


    quint32 numTracksIn( QString playlistName ) const;

    quint32 allPlaylists(
                       QList<Model::SavedPlaylist *> &playlists );

    QString uniqueName() const;

    QString module()  const;

    QString displayName() const;

    bool init();

    int rowCount(const QModelIndex &parent) const;

    int columnCount(const QModelIndex &parent) const;

    QVariant data(const QModelIndex &index, int role) const;

    QVariant headerData(int section,
                        Qt::Orientation orientation, int role) const;

    QModelIndex index(int row, int column, const QModelIndex &parent) const;

    QModelIndex parent(const QModelIndex &child) const;

    bool hasChildren( const QModelIndex &parent ) const;

    Qt::ItemFlags flags( const QModelIndex &index ) const;

    bool setData(const QModelIndex &index, const QVariant &value, int role);


    static QString COMPONENT_NAME;

    static QString COMPONENT_MODULE;

private:

    QHash< QString, Model::SavedPlaylist *> m_playlists;

    QHash< QString, QList< QString > *> m_playlistToTrackIds;

    QList< Model::SavedPlaylist *> *m_itemList;

    void resetItemList();
};
}
}

#endif // STANDARDPLAYLISTMANAGER_H
